// @ts-nocheck
import media from '@ohos.multimedia.media';
var audiorecorder = media.createAudioRecorder();
var audioplayer = media.createAudioPlayer();
export default {
    data: {
        title: 'World'
    },
    play(){
        audioplayer.src = 'common/music/demo.mp3';
        audioplayer.play();
        audioplayer.on('play', (err, action) => {
          if (err) {
             console.log('err returned in play() callback');
             return;
          }
          console.log('start to play');
//          audioplayer.pause();


        })
    },
    pause(){
        audioplayer.src = 'common/mydream.mp3';
        audioplayer.on('pause', (err, action) => {
          if (err) {
             console.log('err returned in pause() callback');
             return;
          }
          console.log('playback pause');
        });
        audioplayer.pause();
    },
    stop(){
        audioplayer.src = 'common/mydream.mp3';
        audioplayer.on('stop',(err, action) => {
          if (err) {
             console.log('err returned in stop() callback');
             return;
          }
          console.log('playback stop');
        });
        audioplayer.stop();
    },
  seek(){
      audioplayer.src = 'common/mydream.mp3';
      audioplayer.on('timeupdate', (err, action) => {
          if (err) {
              console.log('err returned in seek() callback');
              return;
          }
          var newTime = audioplayer.currenTime;
          if(newTime = 30000) {
              console.info('Seek success, new time : ' + newTime);
          } else {
              console.info('Seek Failed');
          }
      });
      audioplayer.seek(30000);
  },
    setVolume(){
        audioplayer.src = 'common/mydream.mp3';
        audioplayer.on('volumeChange', (err, action) => {
          if (err) {
             console.log('err returned in setVolume() callback');
             return;
          }
          console.log('playback volume change');
        });
        audioplayer.setVolume(1);
    },

    release(){
        audioplay.release();
    },
    startRecord(){
        audiorecorder.start();
        let config = {
            Encoder : 3,
            encodeBitRate : 8000,
            sampleRate : 8000,
            numberOfChannel : 1,
            FileFormat : 1,
            filePath : "internal://app/example.m4a"
        };
        audiorecorder.prepare(config);
        audiorecorder.on('prepare', (err, action) => {
          if (err) {
             console.log('err returned in prepare callback');
             return;
          }
          console.log('prepare success');
        });
    },
    pauseRecord(){
        audiorecorder.pause();
    },
    resumeRecord(){
        audiorecorder.resume();
    },
    stopRecord(){
        audiorecorder.stop();
         audiorecorder.on('stop', (err, action) => {
          if (err) {
             console.log('err returned in prepare callback');
             return;
          }
          console.log('stop success');
          console.log(action)
        });
    },
    seekRecord(){},
    resetRecord(){
        audiorecorder.reset();
    },
    releaseRecord(){
        audiorecorder.release();
    }

}
